﻿using System.Collections.Generic;
using PerceptiveMCAPI.Types;
//
namespace PerceptiveMCAPI
{
   internal static class campaignSegmentTest_Validator
   {
      // match
      internal static Api_ValidatorMessage match_valid( string match )
      {
         if ( match != "any" && match != "all" )
         {
            return Validator.FormatMsg( EnumValues.MessageLevel.Error, "match",
               "'match' value must be either 'any' or 'all'" );
         }
         return null;
      }
      // segment_conditions
      internal static Api_ValidatorMessage conditions_valid( List<campaignSegmentCondition> list )
      {
         if ( list.Count < 1 )
         {
            return Validator.FormatMsg( EnumValues.MessageLevel.Error, "campaignSegmentCondition",
               "At least one segment condition must be specified." );
         }
         else
         {
            foreach ( campaignSegmentCondition cond in list )
            {
               if ( string.IsNullOrEmpty( cond.field ) ||
             string.IsNullOrEmpty( cond.op ) ||
             string.IsNullOrEmpty( cond.value ) )
               {
                  return Validator.FormatMsg( EnumValues.MessageLevel.Error, "condition",
                     string.Format( "Missing entries for a 'condition' were found; condition -- field: {0}, op: {1}, value: {2}",
                        cond.field, cond.op, cond.value ) );
               }
            }
         }
         return null;
      }
   }
}
